# -*- coding: utf-8 -*-
import os
import sys
import zipimport

# zipimport导入appengine_utilities
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../libs/appengine_utilities.zip'))
from appengine_utilities import sessions

def require_auth(func):
    '''要求必须经过授权'''
    def _wrapper(rhi, *args, **kwargs):
        session = sessions.Session()
        if 'authed' in session:
            return func(rhi, *args, **kwargs)
        else:
            rhi.redirect('/')
    return _wrapper

def add_authed_session():
    session = sessions.Session()
    session['authed'] = 'authed'    

def remove_authed_session():
    session = sessions.Session()
    session.delete('authed')